library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity led8 is
  generic(n:integer :=50000000);   
  port (
        clk:in std_logic;
        reset:in std_logic;
        led8s:out std_logic_vector(9 downto 0));
end led8;
 
architecture behave of led8 is
  signal count :integer range n-1 downto 0:=n-1;   --
  signal q1:std_logic;
  signal count2 :std_logic_vector(3 downto 0);
  
begin

process(clk)
 begin
 if rising_edge(clk) then   --如果是时钟的上升沿则
     count<=count-1;
     if count>=n/2 then
       q1<='0';
     else
       q1<='1';
     end if;
     if count<=0 then
       count<=n-1;
     end if;
  end if;
end process;

process(q1)      
begin
  if reset='0' then    --复位重置，按下button1就又从第一个灯开始灭起
    count2<="0000";
  elsif rising_edge(q1)then    --
    if count2="1001" then
      count2<="0000";
    else
     count2<=count2+1;    --计数器+1就是对应灯的移位
    end if;
  end if;
end process;


 
 process(count2)    --灯的移动
 begin
   case count2 is
     when "0000" => led8s<="1111111110";   --哪个位是0就是哪个led灯灭
     when "0001" => led8s<="1111111101";
     when "0010" => led8s<="1111111011";
     when "0011" => led8s<="1111110111";
     when "0100" => led8s<="1111101111";
     when "0101" => led8s<="1111011111";
     when "0110" => led8s<="1110111111";
     when "0111" => led8s<="1101111111";
	  when "1000" => led8s<="1011111111";
	  when "1001" => led8s<="0111111111";
	  when others => led8s<="0000000000";
   end case;
 end process;
end behave;

